//满意度
import { Behaviour } from "../Behaviour";
import { getGameObjectById } from "../../engine";
import { TextRenderer } from "../TextRenderer";
import { BitmapRenderer } from "../BitmapRenderer";
import { number } from "../validators/number";
import { string } from "../validators/string";
import { System } from "./System";
import { ClockSystem } from "./ClockSystem";
import { OrderButtonClick } from "../../behaviours/OrderButtonClick";
import { Tip } from "../../behaviours/Tip";


//两个小时满意度降为零
export class SatisfactionSystem extends System{

    satiNum:number

    //是否重置满意度
    reset:boolean
    //是否上菜了
    giveToGuest:boolean

    tip:number
    startSati:boolean

    onStart(){
        this.satiNum = 100
        this.tip = 0
        this.giveToGuest = false

        //this.Satisfaction()
        this.startSatisfaction()
        this.startSati = false
    }

    startSatisfaction(){
        this.startSati = getGameObjectById('UI_satisfaction_text').getBehaviour(Tip).startSati
        this.reset = getGameObjectById('UI_satisfaction_text').getBehaviour(Tip).reset
        
        //console.log("满意度是否重置：" + this.reset)

        //满意度重置
        if(this.reset){
            this.satiNum = 105
            getGameObjectById('UI_satisfaction_text').getBehaviour(TextRenderer).text = "100"
            getGameObjectById('UI_satisfaction_smileFace').getBehaviour(BitmapRenderer).source =  "./assets/images/UI_satisfaction_smileFace.png"
            //console.log("满意度重置了！！当前文字：" + getGameObjectById('UI_satisfaction_text').getBehaviour(TextRenderer).text)
            getGameObjectById('UI_satisfaction_text').getBehaviour(Tip).reset = false
        }
        //满意度开始减少
        if(this.startSati){
            //console.log("满意度开始减少了！！")
            this.Satisfaction()
            getGameObjectById('UI_satisfaction_text').getBehaviour(Tip).startSati = false
        }     
                                 
        setTimeout(() => {            
            this.startSatisfaction()
        }, 500);
    }

    Satisfaction(){
            if(this.satiNum > 5){
                this.satiNum -= 5
            }else{
                this.satiNum = 0
            }
            //console.log(this.satiNum)

            //满意度40换成愤怒表情
            if(this.satiNum < 41){
                getGameObjectById('UI_satisfaction_smileFace').getBehaviour(BitmapRenderer).source =  "./assets/images/UI_satisfaction_angryFace.png"
            }
            getGameObjectById('UI_satisfaction_text').getBehaviour(TextRenderer).text = this.satiNum.toString()

        setTimeout(() => {
            //如果没给客人了就循环
            this.giveToGuest = getGameObjectById('UI_satisfaction_text').getBehaviour(Tip).giveToGuest
            if(!this.giveToGuest){
                //循环调用
                this.Satisfaction()
            }else{//如果给客人了就return，重置giveToGuest
                //console.log("已经给客人了，退出循环")
                getGameObjectById('UI_satisfaction_text').getBehaviour(Tip).giveToGuest = false
                //console.log("已经给客人了，退出循环。重置给客人：" + getGameObjectById('UI_satisfaction_text').getBehaviour(Tip).giveToGuest)
                return 666
            }            
        }, 4000);
    }

}